from extensions import db

# 定义 Attendance 模型
class Attendance(db.Model):
    __tablename__ = 'attendancetbl'  # 指定表名
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.Date, nullable=False)  # 日期
    morning_absent = db.Column(db.String(500), nullable=True)  # 早读缺勤人员名单（存储为 JSON 字符串）
    exercise_absent = db.Column(db.String(500), nullable=True)  # 课间操缺勤人员名单
    school_over_absent = db.Column(db.String(500), nullable=True)  # 放学缺勤人员名单
    phone_absent = db.Column(db.String(500), nullable=True)  # 手机未交人员名单

    def __repr__(self):
        return f"<Attendance(id={self.id}, \
            date={self.date}, \
            morning_absent={self.morning_absent}, \
            exercise_absent={self.exercise_absent},\
            school_over_absent={self.school_over_absent},\
            phone_absent={self.phone_absent})>"



class StudentAttendanceSummary(db.Model):
    __tablename__ = 'stu_attendance_tbl'
    stu_name = db.Column(db.String(50), primary_key=True)
    morning_absent_times = db.Column(db.Integer, default=0)
    exercise_absent_times = db.Column(db.Integer, default=0)
    school_over_absent_times = db.Column(db.Integer, default=0)
    phone_absent_times = db.Column(db.Integer, default=0)

    def __repr__(self):
        return f"<StudentAttendanceSummary(stu_name={self.stu_name}, \
            morning_absent_times={self.morning_absent_times}, \
            exercise_absent_times={self.exercise_absent_times},\
            school_over_absent_times={self.school_over_absent_times},\
            phone_absent_times={self.phone_absent_times})>"